/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-09 20:54:20
 * @LastEditTime: 2019-09-14 12:29:00
 * @LastEditors: Please set LastEditors
 */
const express = require('express')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const passport = require('passport')
const app = express()


// 引入users.js
const users = require('./routes/api/users')
const profiles = require('./routes/api/profiles')

// DB config
const db = require('./config/keys').mongoURL

// body-parse
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json() )




// connect to mongoDB
mongoose.connect(db)
    .then(()=>console.log("MongoDB connected"))
    .catch(err=>console.log(err))
    
// passport初始化
app.use(passport.initialize());
require('./config/passport')(passport);



app.get('/',(req,res)=>{
    res.end('Hello world')
})

// 使用router
app.use('/api/users',users)
app.use('/api/profile',profiles)

const port = process.env.PORT || 5000

app.listen(port,()=>{
    console.log('Server is running on '+ port)
})